#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <grp.h>
#include <string.h>
#include <time.h>

int logger(struct tm *timeinfo, char *nick, char *message)
{

	int line = 0;
	char *path;
	FILE *file;
	char line_buffer[BUFSIZ];
	file = fopen("settings.txt", "r");

	while(fgets(line_buffer, sizeof(line_buffer), file)){
		if(line == 1){
		path = line_buffer;
		path[strlen(path)] = 0;
	}
	line++;
	}
	fclose(file);

	//printf("%s\n", path);

	file = fopen(path, "a");
	//fprintf(file,"%s\n", message);
	if(strcmp(nick, "none") != 0){
	fprintf(file, "%02d:%02d:%02d %s %s\n", 
				timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, nick, message);
	}
	else{
		fprintf(file, "%02d:%02d:%02d %s\n", 
				timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, message);
	}
	fclose(file);
}